package com.stone.design.patterns.singleton;

/**
 * @author Stone
 * @version V1.0
 * @description: 单例模式 双重加锁 ，双重加锁在1.4及以前是不适用的
 *   用双重加锁 优化性能
 * 私有化构造器 通过静态方法实例化对象
 * @date 4/12/18 20:47
 * @email redsstone@163.com
 */
public class SingletonA {

    private volatile static SingletonA mSingleton;

    private SingletonA() {}

    public static synchronized SingletonA getInstance() {

        if (mSingleton == null) {
            // 实例如果没有被创建 则加锁
            synchronized (Singleton.class) {
                if (mSingleton == null) {
                    mSingleton = new SingletonA();
                }
            }

        }
        return mSingleton;
    }

}
